//
//  Rank_ReceiveGiftListController.m
//  YLProject
//
//  Created by 张伯林 on 2018/2/5.
//  Copyright © 2018年 WY. All rights reserved.
//

#import "Rank_ReceiveGiftListController.h"
#import "Rank_ReceiveGiftListCell.h"
#import "Rank_PeopleInfoController.h"
#import "Rank_GiftListSortView.h"
#import "ZZPopoverWindow.h"
#import "Rank_ReceiveRecordListController.h"
@interface Rank_ReceiveGiftListController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataSource;
@property(nonatomic,strong)ZZPopoverWindow *popover;
@end

@implementation Rank_ReceiveGiftListController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"收到的礼物列表";
    AdjustsScrollViewInsetNever(self, self.tableView)
    [self setNavBarButton];
    [self.view addSubview:self.tableView];
}
-(void)setNavBarButton{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(0, 5,34,34);
    [rightButton setTitle:@"排序" forState:UIControlStateNormal];
    [rightButton setTitle:@"排序" forState:UIControlStateHighlighted];
    [rightButton setTitleColor:kHEXCOLOR(@"5a4c4c") forState:UIControlStateNormal];
    [rightButton setTitleColor:kHEXCOLOR(@"5a4c4c") forState:UIControlStateHighlighted];
    rightButton.titleLabel.font = YLFont(14);
    [[rightButton  rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSLog(@"礼物列表右按钮");
        Rank_GiftListSortView *sortView = [Rank_GiftListSortView popViewBlock:^(NSString *att){
            if ([att isEqualToString:@"integralGift"]) {
                YLLog(@"礼物积分");
            }else{
                YLLog(@"赠送时间");
            }
        }];
        sortView.backgroundColor = [UIColor clearColor];
        self.popover                    = [[ZZPopoverWindow alloc] init];
        // self.popover.popoverPosition = ZZPopoverPositionRight; // 指定contentView在箭头的哪个方向，默认自己会选择
         self.popover.backgroundColor = [UIColor blackColor]; // 指定弹框背景色
        // self.popover.showArrow       = NO; // 是否显示箭头，默认YES
        self.popover.contentView        = sortView; // 指定contentView
        self.popover.didShowHandler = ^() {
            NSLog(@"Did show");
        };
        self.popover.didDismissHandler = ^() {
            NSLog(@"Did dismiss");
        };
        [self.popover showAtView:rightButton];
        
    }];
    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc]initWithCustomView:rightButton]];
}
#pragma mark ---tableView代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    Rank_ReceiveGiftListCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Rank_ReceiveGiftListCell class])];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.block = ^(NSString *userId) {
        YLLog(@"%@",userId);
        Rank_PeopleInfoController *rank_info = [[Rank_PeopleInfoController alloc]init];
        [self.navigationController pushViewController:rank_info animated:YES];
    };
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    Rank_ReceiveRecordListController *list = [[Rank_ReceiveRecordListController alloc]init];
    [self.navigationController pushViewController:list animated:YES];
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height - (STATUS_BAR_HEIGHT + 44)) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.showsVerticalScrollIndicator = NO;
//        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass(Rank_ReceiveGiftListCell.class) bundle:nil] forCellReuseIdentifier:NSStringFromClass(Rank_ReceiveGiftListCell.class)];
        _tableView.tableFooterView = [UIView new];
        _tableView.backgroundColor = kHEXCOLOR(@"f4f5f7");
    }
    return _tableView;
}
-(NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
